package com.app.micaihu.view.lunch.dialog;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.app.micaihu.R;
import com.app.micaihu.base.BaseOldDialog;
import com.app.micaihu.configure.Config;
import com.blankj.utilcode.util.ClickUtils;

public class FirstPermissionDialog extends BaseOldDialog {

    public static FirstPermissionDialog getFirstDialog(Bundle bundle) {
        FirstPermissionDialog firstPermissionDialog = new FirstPermissionDialog();
        firstPermissionDialog.setArguments(bundle);
        return firstPermissionDialog;
    }

    private Button btnOpen;
    private ImageView ivClose;
    private LinearLayout llPhoneState, llSd;
    private OnOpenClick onOpenClick;
    private boolean phoneState, writeStorage;

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_first_permission;
    }

    @Override
    protected void init(Bundle bundle) {
        if (bundle != null) {
            phoneState = bundle.getBoolean(Config.Extra.phoneState, false);
            writeStorage = bundle.getBoolean(Config.Extra.writeStorage, false);
        }
        btnOpen = thisView.findViewById(R.id.btnOpen);
        ivClose = thisView.findViewById(R.id.ivClose);
        llPhoneState = thisView.findViewById(R.id.llPhoneState);
        llSd = thisView.findViewById(R.id.llSd);

    }

    @Override
    protected void setData() {
        setState(phoneState, writeStorage);
    }

    public void setState(boolean phoneState, boolean writeStorage) {
        this.phoneState = phoneState;
        this.writeStorage = writeStorage;
        if (phoneState) {
            llPhoneState.setVisibility(View.GONE);
        } else {
            llPhoneState.setVisibility(View.VISIBLE);
        }
        if (writeStorage) {
            llSd.setVisibility(View.GONE);
        } else {
            llSd.setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected void setListener() {
        ivClose.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
            @Override
            public void onDebouncingClick(View v) {
                if (onOpenClick != null) {
                    FirstPermissionDialog.this.dismiss();
                    onOpenClick.onCloseClick();
                }
            }
        });
        btnOpen.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
            @Override
            public void onDebouncingClick(View v) {
                if (onOpenClick != null) {
                    onOpenClick.onOpenClick();
                }
            }
        });
    }

    public interface OnOpenClick {
        void onOpenClick();

        void onCloseClick();
    }

    public void setOnOpenClick(OnOpenClick onOpenClick) {
        this.onOpenClick = onOpenClick;
    }
}
